<%@ page contentType="text/html;charset=UTF-8" language="java" pageEncoding="UTF-8"%>
<html>
<head>
    <link rel="shortcut icon" href="/assets/images/icon.png">
    <link rel="stylesheet" type="text/css" href="/css/zhuce.css" />
    <script src="https://libs.baidu.com/jquery/1.11.3/jquery.min.js"></script>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
    <script src="http://code.jquery.com/jquery-latest.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <script src="/assets/js/citypicker/citydistpicker.data.js"></script>
    <script src="/assets/js/citypicker/distpicker.js"></script>
    <script src="/assets/js/citypicker/citymain.js"></script>
    <script src="/assets/js/getshouzimu.js"></script>
</head>
<body>
<!-- 模态框（Modal） -->
<div class="modal fade" id="myModal" style="position: absolute; top: 50%;left: 50%; transform: translateX(-50%) translateY(-50%);" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×
                </button>
                <h2 class="modal-title" id="myModalLabel" style="color:red;">
                    恭喜您！注册成功。
                </h2>
            </div>
            <div class="modal-body">
                初始账号状态为冻结状态，请联系服务商开通账号，点击确定跳转到登录界面。<br><br>联系方式：<a href="http://www.tjsiqi.com/">020-66351935/13132099800</a>(年四辉)
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">
                    关闭
                </button>
                <button type="button" onclick="location.href='/logout.page'" id="btnLogin" class="btn btn-primary">
                    确定
                </button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div><!-- /.modal -->
<div class="container" >
    <div class="col-md-6 col-md-offset-3" >
        <form action="#" id="formc" >
            <%--<form  id="formc" >--%>
                <%--<button class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal">--%>
                    <%--开始演示模态框--%>
                <%--</button>--%>
            <div>
                <h3 >搅拌站信息</h3>(注：搅拌站信息将供微信小程序客户选择使用，请详细填写！)<hr style=" margin-top:0px;border-top: 3px solid yellowgreen"/>
            </div>

            <div class="form-group has-feedback">
                <label for="jbzname" >搅拌站名称</label>
                <div class="input-group">
                    <span class="input-group-addon"><span class="glyphicon glyphicon-th-large"></span></span>
                    <input id="jbzname" name="mc" onblur="getszm()" class="form-control jbzname" placeholder="请输入搅拌站名称"required minlength="2" maxlength="25" type="text">
                </div>

                <span style="color:red;display: none;" class="tips"></span>
                <span style="display: none;" class=" glyphicon glyphicon-remove form-control-feedback"></span>
                <span style="display: none;" class="glyphicon glyphicon-ok form-control-feedback"></span>
            </div>

            <%--<h4 class="page-header">所属省市区</h4>--%>
            <div class="docs-methods" style="margin-bottom: 15px">
                <label >搅拌站所属省市区</label>
                    <div id="distpicker" class="form-inline">
                        <div class="form-group">
                            <label class="sr-only"  for="province">Province</label>
                            <select class="form-control" name="province" id="province"></select>
                        </div>
                        <div class="form-group">
                            <label class="sr-only" for="city">City</label>
                            <select class="form-control" name="city" id="city"></select>
                        </div>
                        <div class="form-group">
                            <label class="sr-only" for="district">District</label>
                            <select class="form-control" name="district" id="district"></select>
                        </div>
                    </div>
            </div>

            <div class="form-group has-feedback">
                <label for="jbzplace" >搅拌站详细地址</label>
                <div class="input-group">
                    <span class="input-group-addon"><span class="glyphicon glyphicon-map-marker"></span></span>
                    <input id="jbzplace" name="dz"  class="form-control jbzplace" placeholder="请输入搅拌站详细地址" required minlength="2" maxlength="50" >
                </div>

                <span style="color:red;display: none;" class="tips"></span>
                <span style="display: none;" class="glyphicon glyphicon-remove form-control-feedback"></span>
                <span style="display: none;" class="glyphicon glyphicon-ok form-control-feedback"></span>
            </div>

            <div class="form-group has-feedback">
                <label for="jbzcontract" >搅拌站联系人</label>
                <div class="input-group">
                    <span class="input-group-addon"><span class="glyphicon glyphicon-user"></span></span>
                    <input id="jbzcontract" name="fzr" class="form-control jbzcontract" placeholder="请输入搅拌站联系人" minlength="2" maxlength="20" >
                </div>
                <span style="color:red;display: none;" class="tips"></span>
                <span style="display: none;" class="glyphicon glyphicon-remove form-control-feedback"></span>
                <span style="display: none;" class="glyphicon glyphicon-ok form-control-feedback"></span>
            </div>

            <div class="form-group has-feedback">
                <label for="contractphone" >联系电话</label>
                <div class="input-group">
                    <span class="input-group-addon"><span class="glyphicon glyphicon-phone-alt"></span></span>
                    <input id="contractphone" name="dh" class="form-control contractphone" placeholder="请输入手机/电话号码" minlength="10" maxlength="15" type="text">
                </div>
                <span style="color:red;display: none;" class="tips"></span>
                <span style="display: none;" class="glyphicon glyphicon-remove form-control-feedback"></span>
                <span style="display: none;" class="glyphicon glyphicon-ok form-control-feedback"></span>
            </div>

            <div style="margin-bottom: 15px">
                <label  >搅拌站类型</label>
                <%--<div class="well well-sm" id="jbzlx" data-toggle="tooltip" data-placement="bottom" title="搅拌站类型">ces</div>--%>
                <div class="form-inline" style="margin-bottom: 15px;">
                    <div class="form-group" style="width: 22%;margin-right: 2%">
                        <div class="input-group">
					<span class="input-group-addon">
						<input  id="ck1" name="xlx" value="0" type="checkbox" checked style="width:18px;height:18px">
					</span>
                            <span style="color:red;display: none;" class="tips"></span>
                            <span style="display: none;" class="glyphicon glyphicon-remove form-control-feedback"></span>
                            <span style="display: none;" class="glyphicon glyphicon-ok form-control-feedback"></span>
                            <input type="text"  value="商砼"  disabled="true" class="form-control"  >
                            <span style="color:red;display: none;" class="tips"></span>
                            <span style="display: none;" class="glyphicon glyphicon-remove form-control-feedback"></span>
                            <span style="display: none;" class="glyphicon glyphicon-ok form-control-feedback"></span>
                        </div><!-- /input-group -->
                    </div>
                    <div class="form-group" style="width: 22%;margin-right: 2%">
                        <div class="input-group">
					<span class="input-group-addon">
						<input  id="ck2" name="xlx" type="checkbox" value="1" style="width:18px;height:18px">
					</span>
                            <span style="color:red;display: none;" class="tips"></span>
                            <span style="display: none;" class="glyphicon glyphicon-remove form-control-feedback"></span>
                            <span style="display: none;" class="glyphicon glyphicon-ok form-control-feedback"></span>
                            <input type="text"  value="沥青"  class="form-control" disabled  >
                            <span style="color:red;display: none;" class="tips"></span>
                            <span style="display: none;" class="glyphicon glyphicon-remove form-control-feedback"></span>
                            <span style="display: none;" class="glyphicon glyphicon-ok form-control-feedback"></span>
                        </div><!-- /input-group -->
                    </div>
                    <div class="form-group" style="width: 22%;margin-right: 2%">
                        <div class="input-group">
					<span class="input-group-addon">
						<input  id="ck3" name="xlx" value="2" type="checkbox" style="width:18px;height:18px">
					</span>
                            <span style="color:red;display: none;" class="tips"></span>
                            <span style="display: none;" class="glyphicon glyphicon-remove form-control-feedback"></span>
                            <span style="display: none;" class="glyphicon glyphicon-ok form-control-feedback"></span>
                            <input type="text"  value="砂浆" disabled="true" class="form-control"  >
                            <span style="color:red;display: none;" class="tips"></span>
                            <span style="display: none;" class="glyphicon glyphicon-remove form-control-feedback"></span>
                            <span style="display: none;" class="glyphicon glyphicon-ok form-control-feedback"></span>
                        </div><!-- /input-group -->
                    </div>
                    <div class="form-group" style="width: 22%;margin-right: 2%">
                        <div class="input-group">
					<span class="input-group-addon">
						<input  id="ck4" name="xlx" value="3" type="checkbox" style="width:18px;height:18px">
					</span>
                            <span style="color:red;display: none;" class="tips"></span>
                            <span style="display: none;" class="glyphicon glyphicon-remove form-control-feedback"></span>
                            <span style="display: none;" class="glyphicon glyphicon-ok form-control-feedback"></span>
                            <input type="text"  value="水稳" disabled="true" class="form-control"  >
                            <span style="color:red;display: none;" class="tips"></span>
                            <span style="display: none;" class="glyphicon glyphicon-remove form-control-feedback"></span>
                            <span style="display: none;" class="glyphicon glyphicon-ok form-control-feedback"></span>
                        </div><!-- /input-group -->
                    </div>
                </div>
            </div>

            <div class="form-group has-feedback">
                <label for="jianjie" >搅拌站简介</label>
                <div class="input-group">
                    <span class="input-group-addon"><span class="glyphicon glyphicon-tags"></span></span>
                    <input id="jianjie" name="bz" class="form-control jianjie" placeholder="请输入公司简介" required minlength="2" maxlength="80" type="text">
                </div>
                <span style="color:red;display: none;" class="tips"></span>
                <span style="display: none;" class="glyphicon glyphicon-remove form-control-feedback"></span>
                <span style="display: none;" class="glyphicon glyphicon-ok form-control-feedback"></span>
            </div>

            <div class="form-group has-feedback">
                <label for="jbzCode"  data-toggle="tooltip" data-placement="bottom" title="搅拌站编号自动生成，无需填写">搅拌站编号(自动生成，无需填写)</label>
                <div class="input-group">
                    <span class="input-group-addon"><span class="glyphicon glyphicon-asterisk" data-toggle="tooltip" data-placement="bottom" title="搅拌站编号自动生成，无需填写"></span></span>
                    <input id="jbzCode" name="code" data-toggle="tooltip" data-placement="bottom" title="搅拌站编号自动生成，无需填写" class="form-control jbzCode" placeholder="搅拌站编号自动生成，无需填写" type="text" readonly>
                </div>
                <span style="color:red;display: none;" class="tips"></span>
                <span style="display: none;" class="glyphicon glyphicon-remove form-control-feedback"></span>
                <span style="display: none;" class="glyphicon glyphicon-ok form-control-feedback"></span>
                <%--<div class="well well-sm" id="jbzcode" name="code" data-toggle="tooltip" data-placement="bottom" title="搅拌站编号自动生成，无需填写"></div>--%>
            </div>



            <div>
            <h3 >用户信息</h3>(注：用户信息中手机和邮箱都可为登录账号，请详细填写！)<hr style=" margin-top:0px;border-top: 3px solid yellowgreen"/>
            </div>
            <div class="form-group has-feedback">
                <label for="username" >姓名</label>
                <div class="input-group">
                    <span class="input-group-addon"><span class="glyphicon glyphicon-user"></span></span>
                    <input id="username" name="username" class="form-control username" placeholder="请输入用户名" required maxlength="20" type="text">
                </div>

                <span style="color:red;display: none;" class="tips"></span>
                <span style="display: none;" class=" glyphicon glyphicon-remove form-control-feedback"></span>
                <span style="display: none;" class="glyphicon glyphicon-ok form-control-feedback"></span>
            </div>

            <div class="form-group has-feedback">
                <label for="password" >密码</label>
                <div class="input-group">
                    <span class="input-group-addon"><span class="glyphicon glyphicon-lock"></span></span>
                    <input id="password" name="password" class="form-control password" placeholder="请输入密码" required maxlength="20" type="password">
                </div>

                <span style="color:red;display: none;" class="tips"></span>
                <span style="display: none;" class="glyphicon glyphicon-remove form-control-feedback"></span>
                <span style="display: none;" class="glyphicon glyphicon-ok form-control-feedback"></span>
            </div>

            <div class="form-group has-feedback">
                <label for="passwordConfirm" >确认密码</label>
                <div class="input-group">
                    <span class="input-group-addon"><span class="glyphicon glyphicon-lock"></span></span>
                    <input id="passwordConfirm" name="passwordConfirm" class="form-control passwordConfirm" required placeholder="请再次输入密码" maxlength="20" type="password">
                </div>
                <span style="color:red;display: none;" class="tips"></span>
                <span style="display: none;" class="glyphicon glyphicon-remove form-control-feedback"></span>
                <span style="display: none;" class="glyphicon glyphicon-ok form-control-feedback"></span>
            </div>

            <div class="row">
                <div class="col-xs-7">
                    <div class="form-group has-feedback">
                        <label for="idcode-btn" >验证码</label>
                        <div class="input-group">
                            <span class="input-group-addon"><span class="glyphicon glyphicon-qrcode"></span></span>
                            <input id="idcode-btn"  class="form-control idcode-btn" placeholder="请输入验证码" required maxlength="4" type="text">
                        </div>
                        <span style="color:red;display: none;" class="tips"></span>
                        <span style="display: none;" class="glyphicon glyphicon-remove form-control-feedback"></span>
                        <span style="display: none;" class="glyphicon glyphicon-ok form-control-feedback"></span>
                    </div>
                </div>
                <div class="col-xs-5" style="padding-top: 30px">
                    <div id="idcode" style="background: transparent;"></div>
                </div>
            </div>

            <div class="form-group has-feedback">
                <label for="phoneNum" >手机号码</label>
                <div class="input-group">
                    <span class="input-group-addon"><span class="glyphicon glyphicon-phone"></span></span>
                    <input id="phoneNum" name="telephone" class="form-control phoneNum" placeholder="请输入手机号码" required maxlength="11" type="text">
                </div>
                <span style="color:red;display: none;" class="tips"></span>
                <span style="display: none;" class="glyphicon glyphicon-remove form-control-feedback"></span>
                <span style="display: none;" class="glyphicon glyphicon-ok form-control-feedback"></span>
            </div>

            <div class="form-group has-feedback">
                <label for="mail" >邮箱</label>
                <div class="input-group">
                    <span class="input-group-addon"><span class="	glyphicon glyphicon-envelope"></span></span>
                    <input id="mail" name="mail" class="form-control mail" placeholder="请输入邮箱" required type="text">
                </div>
                <span style="color:red;display: none;" class="tips"></span>
                <span style="display: none;" class="glyphicon glyphicon-remove form-control-feedback"></span>
                <span style="display: none;" class="glyphicon glyphicon-ok form-control-feedback"></span>
            </div>

            <div class="row">
                <%--<div class="col-xs-7">--%>
                    <%--<div class="form-group has-feedback">--%>
                        <%--<label for="idcode-btn" >校验码</label>--%>
                        <%--<div class="input-group">--%>
                            <%--<span class="input-group-addon"><span class="glyphicon glyphicon-qrcode"></span></span>--%>
                            <%--<input id="idcode-btn" class="form-control" placeholder="请输入校验码" maxlength="6" type="text">--%>
                        <%--</div>--%>
                        <%--<span style="color:red;display: none;" class="tips"></span>--%>
                        <%--<span style="display: none;" class="glyphicon glyphicon-remove form-control-feedback"></span>--%>
                        <%--<span style="display: none;" class="glyphicon glyphicon-ok form-control-feedback"></span>--%>
                    <%--</div>--%>
                <%--</div>--%>
                <%--<div class="col-xs-5 text-center" style="padding-top: 26px">--%>
                    <%--<button type="button" id="loadingButton" class="btn btn-primary" autocomplete="off">获取短信校验码</button>--%>
                <%--</div>--%>

                    <%--<button type="submit">注册</button>--%>

            </div>

        </form>
        <div class="form-group">
            <input class="form-control btn btn-primary" id="submit" value="立&nbsp;&nbsp;即&nbsp;&nbsp;注&nbsp;&nbsp;册" type="submit">
        </div>

        <div class="form-group">
            <input value="重置" id="reset" class="form-control btn btn-danger" type="reset">
        </div>
    </div>
</div>



<script>
var settings = {
    e: 'idcode',
    codeType: {
        name: 'follow',
        len: 4
    }, //len是修改验证码长度的
    codeTip: '换个验证码?',
    inputID: 'idcode-btn' //验证元素的ID
};

var _set = {
    storeLable: 'codeval',
    store: '#ehong-code-input',
    codeval: '#ehong-code'
}

$.idcode = {
    getCode: function(option) {
        _commSetting(option);
        return _storeData(_set.storeLable, null);
    },
    setCode: function(option) {
        _commSetting(option);
        _setCodeStyle("#" + settings.e, settings.codeType.name, settings.codeType.len);

    },
    validateCode: function(option) {
        _commSetting(option);
        var inputV;
        if (settings.inputID) {
            inputV = $('#' + settings.inputID).val();

        } else {
            inputV = $(_set.store).val();
        }
        if (inputV.toUpperCase() == _storeData(_set.storeLable, null).toUpperCase()) { //修改的不区分大小写
            return true;
        } else {
            _setCodeStyle("#" + settings.e, settings.codeType.name, settings.codeType.len);
            return false;
        }
    }
};

function getRandomCode(length) {
    if (length > 0) {
        var data = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"];
        var nums = "";
        for (var i = 0; i < length; i++) {
            var r = parseInt(Math.random() * 61);
            nums += data[r];
        }
        return nums;
    } else {
        return false;
    }
}

function getszm(){
    var str = document.getElementById("jbzname").value.trim();
    // alert(str);
    var zh = pinyin.getCamelChars(str);
    // alert(zh);
    var res = getRandomCode(5);
    // alert(res);
    document.getElementById("jbzCode").value = zh+'-'+res;
}

function _commSetting(option) {
    $.extend(settings, option);
}

function _storeData(dataLabel, data) {
    var store = $(_set.codeval).get(0);
    if (data) {
        $.data(store, dataLabel, data);
    } else {
        return $.data(store, dataLabel);
    }
}

function _setCodeStyle(eid, codeType, codeLength) {
    var codeObj = _createCode(settings.codeType.name, settings.codeType.len);
    var randNum = Math.floor(Math.random() * 6);
    var htmlCode = ''
    if (!settings.inputID) {
        htmlCode = '<span><input id="ehong-code-input" type="text" maxlength="4" /></span>';
    }
    htmlCode += '<div id="ehong-code" class="ehong-idcode-val ehong-idcode-val';
    htmlCode += String(randNum);
    htmlCode += '" href="#" onblur="return false" onfocus="return false" oncontextmenu="return false" onclick="$.idcode.setCode()">' + _setStyle(codeObj) + '</div>' + '<span id="ehong-code-tip-ck" class="ehong-code-val-tip" onclick="$.idcode.setCode()">' + settings.codeTip + '</span>';
    $(eid).html(htmlCode);
    _storeData(_set.storeLable, codeObj);
}

function _setStyle(codeObj) {
    var fnCodeObj = new Array();
    var col = new Array('#BF0C43', '#E69A2A', '#707F02', '#18975F', '#BC3087', '#73C841', '#780320', '#90719B', '#1F72D8', '#D6A03C', '#6B486E', '#243F5F', '#16BDB5');
    var charIndex;
    for (var i = 0; i < codeObj.length; i++) {
        charIndex = Math.floor(Math.random() * col.length);
        fnCodeObj.push('<font color="' + col[charIndex] + '">' + codeObj.charAt(i) + '</font>');
    }
    return fnCodeObj.join('');
}

function _createCode(codeType, codeLength) {
    var codeObj;
    if (codeType == 'follow') {
        codeObj = _createCodeFollow(codeLength);
    } else if (codeType == 'calc') {
        codeObj = _createCodeCalc(codeLength);
    } else {
        codeObj = "";
    }
    return codeObj;
}

function _createCodeCalc(codeLength) {
    var code1, code2, codeResult;
    var selectChar = new Array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9');
    var charIndex;
    for (var i = 0; i < codeLength; i++) {
        charIndex = Math.floor(Math.random() * selectChar.length);
        code1 += selectChar[charIndex];

        charIndex = Math.floor(Math.random() * selectChar.length);
        code2 += selectChar[charIndex];
    }
    return [parseInt(code1), parseInt(code2), parseInt(code1) + parseInt(code2)];
}

function _createCodeFollow(codeLength) {
    var code = "";
    var selectChar = new Array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z');

    for (var i = 0; i < codeLength; i++) {
        var charIndex = Math.floor(Math.random() * selectChar.length);
        if (charIndex % 2 == 0) {
            code += selectChar[charIndex].toLowerCase();
        } else {
            code += selectChar[charIndex];
        }
    }
    return code;
}
var regUsername = /^[a-zA-Z_][a-zA-Z0-9_]{4,19}$/;
var regPasswordSpecial = /[~!@#%&=;':",./<>_\}\]\-\$\(\)\*\+\.\[\?\\\^\{\|]/;
var regPasswordAlpha = /[a-zA-Z]/;
var regPasswordNum = /[0-9]/;
var password;
var check = [false, false, false, false,true, true, true, true, true, true, true, true, false, true, false, false, false, false, false,false];

//校验成功函数
function success(Obj, counter) {
    Obj.parent().parent().removeClass('has-error').addClass('has-success');
    $('.tips').eq(counter).hide();
    $('.glyphicon-ok').eq(counter).show();
    $('.glyphicon-remove').eq(counter).hide();
    check[counter] = true;

}

// 校验失败函数
function fail(Obj, counter, msg) {
    Obj.parent().parent().removeClass('has-success').addClass('has-error');
    $('.glyphicon-remove').eq(counter).show();
    $('.glyphicon-ok').eq(counter).hide();
    $('.tips').eq(counter).text(msg).show();
    check[counter] = false;
}

// 搅拌站名称匹配
$('.jbzname').change(function (e) {
    if ($(this).val().length >= 2) {
        e.preventDefault();
        e.stopPropagation();
        var jbzname = $(this).val();
        $.ajax({
            url: "/zhuce/checkjbzName",
            type: "POST",
            data: {
                jbzname: jbzname
            },
            success: function (result) {
                if (result.ret) {
                    success($('.jbzname'), 0);
                } else {
                    fail($('.jbzname'), 0, '该搅拌站名称已被注册,如被冒用，可联系服务商修改');
                }
            }
        })
        // success($(this), 0);
    } else if ($(this).val().length < 2) {
        fail($(this), 0, '搅拌站名称太短，不能少于2个字符');
    } else {
        fail($(this), 0, '搅拌站名称不能含有特殊字符')
    }
});

// 搅拌站地址匹配
$('.jbzplace').change(function () {
    // console.log("----------zhixingl")
    if ($(this).val().length >= 5) {
        success($(this), 1);
        // fail($(this), 0, '用户名太短，不能少于5个字符');
    } else if ($(this).val().length < 5) {
        fail($(this), 1, '搅拌站地址太短，不能少于5个字符');
    } else {
        fail($(this), 1, '搅拌站地址不能含有特殊字符')
    }

});

// 搅拌站联系人匹配
$('.jbzcontract').change(function () {
    // console.log("----------zhixingl")
    if ($(this).val().length >= 2) {
        success($(this), 2);
        // fail($(this), 0, '用户名太短，不能少于5个字符');
    } else if ($(this).val().length < 2) {
        fail($(this), 2, '搅拌站联系人名称太短，不能少于2个字符');
    } else {
        fail($(this), 2, '搅拌站联系人不能含有特殊字符')
    }

});

// 搅拌站简介匹配
$('.jianjie').change(function () {
    // console.log("----------zhixingl")
    if ($(this).val().length >= 5) {
        success($(this), 12);
        // fail($(this), 0, '用户名太短，不能少于5个字符');
    } else if ($(this).val().length < 5) {
        fail($(this), 12, '搅拌站简介太短，不能少于5个字符');
    } else {
        fail($(this), 12, '搅拌站简介不能含有特殊字符')
    }
});

// 搅拌站编号匹配
$('.jbzCode').change(function () {
    if ($(this).val().length > 6) {
        e.preventDefault();
        e.stopPropagation();
        var jbzCode = $(this).val();
        $.ajax({
            url: "/zhuce/checkjbzCode",
            data: {
                jbzCode: jbzCode
            },
            success: function (result) {
                if (result.ret) {
                    success($('.jbzCode'), 13);
                } else {
                    fail($('.jbzCode'), 13, '可通过点击搅拌站名称再点击此输入框去除错误。');
                }
            }
        })
        // success($(this), 18);
    } else {
        fail($(this), 18, '手机号码只能为11位数字');
    }
});

$(function () {
    $("[data-toggle='tooltip']").tooltip();
});

//手机和座机号码
var regMobile = /^1[3|5|8|7]\d{9}$/, regPhone = /^0\d{2,3}-?\d{7,8}$/;
$('.contractphone').change(function () {
    if (regMobile.test($(this).val()) || regPhone.test($(this).val())) {
        success($(this), 3);
    } else {
        fail($(this), 3, '手机或座机格式不正确');
    }
});
// 用户名匹配
$('.username').change(function () {
    console.log("----------zhixingl")
    if ($(this).val().length >= 2) {
        success($(this), 14);
        // fail($(this), 0, '用户名太短，不能少于5个字符');
    } else if ($(this).val().length < 2) {
        fail($(this), 14, '用户名太短，不能少于2个字符');
    } else {
        fail($(this), 14, '用户名不能含有特殊字符')
    }

});

// 密码匹配
// 匹配字母、数字、特殊字符至少两种的函数
function atLeastTwo(password) {
    var a = regPasswordSpecial.test(password) ? 1 : 0;
    var b = regPasswordAlpha.test(password) ? 1 : 0;
    var c = regPasswordNum.test(password) ? 1 : 0;
    return a + b + c;

}

//密码校验
$('.password').change(function () {
    // console.log("----------zhixing2")
    password = $(this).val();

    if ($(this).val().length < 8) {
        fail($(this), 15, '密码太短，不能少于8个字符');
    } else {


        if (atLeastTwo($(this).val()) < 2) {
            fail($(this), 15, '密码中至少包含字母、数字、特殊字符的两种')
        } else {
            success($(this), 15);
        }
    }
});

// 再次输入密码校验
$('.passwordConfirm').change(function () {
    if ($(this).val() == password) {
        success($(this), 16);
    } else {

        fail($(this), 16, '两次输入的密码不一致');
    }

});

// 验证码
$.idcode.setCode();
// $('.container').find('input').eq(8).change(function() {
$('.idcode-btn').change(function () {
    var IsBy = $.idcode.validateCode();
    if (IsBy) {
        success($(this), 17);
    } else {
        fail($(this), 17, '验证码输入错误');
    }
});

// 手机号码
var regPhoneNum = /^[0-9]{11}$/
// $('.container').find('input').eq(9).change(function() {
$('.phoneNum').change(function (e) {
    if (regPhoneNum.test($(this).val())) {
        e.preventDefault();
        e.stopPropagation();
        var phoneNum = $(this).val();
        $.ajax({
            url: "/zhuce/checkPhoneNum",
            data: {
                phoneNum: phoneNum
            },
            success: function (result) {
                if (result.ret) {
                    success($('.phoneNum'), 18);
                } else {
                    fail($('.phoneNum'), 18, '该手机号已被占用，如被冒用，可联系服务商修改');
                }
            }
        })
        // success($(this), 18);
    } else {
        fail($(this), 18, '手机号码只能为11位数字');
    }
});

// 邮箱
var regMail = /^[a-zA-Z0-9_-]+@([a-zA-Z0-9]+\.)+(com|cn|net|org)$/
// $('.container').find('input').eq(9).change(function() {
$('.mail').change(function (e) {
    if (regMail.test($(this).val())) {
        e.preventDefault();
        e.stopPropagation();
        var mail = $(this).val();
        $.ajax({
            url: "/zhuce/checkmail",
            data: {
                mail: mail
            },
            success: function (result) {
                if (result.ret) {
                    success($('.mail'), 19);
                } else {
                    fail($('.mail'), 19, '邮箱已被占用，如被冒用，可联系服务商修改');
                }
            }
        })

    } else {
        fail($(this), 19, '邮箱格式不正确');
    }
});

//短信验证码
// var regMsg = /111111/;
// $('.container').find('input').eq(10).change(function() {
//     if (check[9]) {
//         if (regMsg.test($(this).val())) {
//             success($(this), 10);
//         } else {
//             fail($(this), 10, '短信验证码错误');
//         }
//     } else {
//         $('.container').find('input').eq(9).parent().parent().removeClass('has-success').addClass('has-error');
//     }
//
// });


$('#loadingButton').click(function() {

    if (check[18]) {
        $(this).removeClass('btn-primary').addClass('disabled');

        $(this).html('<span class="red">59</span> 秒后重新获取');
        var secondObj = $('#loadingButton').find('span');
        var secondObjVal = secondObj.text();

        function secondCounter() {

            var secondTimer = setTimeout(function() {
                secondObjVal--;
                secondObj.text(secondObjVal);
                secondCounter();
            }, 1000);
            if (secondObjVal == 0) {
                clearTimeout(secondTimer);
                $('#loadingButton').text('重新获取校验码');
                $('#loadingButton').removeClass('disabled').addClass('btn-primary');

            }
        }

        secondCounter();
    } else {
        $('.container').find('input').eq(18).parent().parent().removeClass('has-success').addClass('has-error');
    }

})

    $('#submit').click(function (e) {
    if (check.includes(false)) {
        console.log("---------baohan" + check + check.includes(false));
        if (!check.every(function (value) {
            return value == true
        })) {
            e.preventDefault();
            for (key in check) {
                if (!check[key]) {
                    $('.container').find('input').eq(key).parent().parent().removeClass('has-success').addClass('has-error')
                }
            }
        }
    } else {
        console.log("-------bu--baohan" + check + check.includes(false));
        $.ajax({
            url: "/zhuce/saveWebUser",
            type: "POST",
            data: $("#formc").serialize(),
            success: function (result) {
                // alert("注册成功！"),
                console.log("-------------zhuce----------");
                if (result.ret) {
                    $('#myModal').modal('show');
                } else {
                    alert(result.msg);
                }
            }
        });
    }
});



$('#reset').click(function() {
    $('input').slice(0, 19).parent().parent().removeClass('has-error has-success');
    $('.tips').hide();
    $('.glyphicon-ok').hide();
    $('.glyphicon-remove').hide();
    check = [false, false, false, false,true, true, true, true, true, true, true, true, false, true, false, false, false, false, false,false];
});
</script></body></html>